package com.example.springbootsfzy.controller.liujinping;

import com.example.springbootsfzy.domain.ConsultationAppointments;
import com.example.springbootsfzy.domain.MemberInfo;
import com.example.springbootsfzy.service.liujinping.ConsultationAppointmentsService;
import com.example.springbootsfzy.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//咨询预约表
@RestController
@RequestMapping("/consultationAppointments")
public class ConsultationAppointmentsController {
    @Autowired
    private ConsultationAppointmentsService consultationAppointmentsService;

    @PostMapping
    public R insert(@RequestBody  ConsultationAppointments record) {
        int result = consultationAppointmentsService.insertSelective(record);
        if (result > 0) {
            return R.ok("添加预约成功");
        }
        return R.error("添加预约失败");
    }

    @DeleteMapping
    public R deleteByPrimaryKey(Long id) {
        int result = consultationAppointmentsService.deleteByPrimaryKey(id);
        if (result > 0) {
            return R.ok("删除预约成功");
        }
        return R.error("删除预约失败");
    }

    @PutMapping
    public R updateByPrimaryKey(@RequestBody  ConsultationAppointments record) {
        int result = consultationAppointmentsService.updateByPrimaryKey(record);
        if (result > 0) {
            return R.ok("修改预约成功");
        }
        return R.error("修改预约失败");
    }

    @PatchMapping
    public R updateByPrimaryKeySelective(@RequestBody  ConsultationAppointments record) {
        int result = consultationAppointmentsService.updateByPrimaryKeySelective(record);
        if (result > 0) {
            return R.ok("修改预约成功");

        }
        return R.error("修改预约失败");
    }

    @GetMapping("/getConsultationAppointments")
    public R selectByPrimaryKey(Long id) {
        ConsultationAppointments result = consultationAppointmentsService.selectByPrimaryKey(id);
        if (result != null) {
            return R.ok(result);

        }
        return R.error("查询预约失败");

    }

    //以咨询师id查询咨询信息  并进行分页和筛选
    @GetMapping("/selectAllByConsultationAppointments")
    public R selectAllByConsultationAppointments(int pageNum,int pageSize,ConsultationAppointments consultationAppointments) {
        PageInfo<ConsultationAppointments> consultationAppointmentsPageInfo = consultationAppointmentsService.selectAllByConsultationAppointments(pageNum, pageSize, consultationAppointments);
        if(!consultationAppointmentsPageInfo.getList().isEmpty()) {
            return R.ok(consultationAppointmentsPageInfo);
        }
        return R.fail("没找到相关信息");
    }



    @GetMapping("/selectAllConsultationAppointments")
    public R selectAll() {
        List<ConsultationAppointments> result = consultationAppointmentsService.selectAll();
        if (result != null) {
            return R.ok(result);
        }
        return R.error("查询预约失败");
    }

    @GetMapping("/selectAllConsultationAppointmentsByPage")
    public R selectAllByPage(Integer memberId) {
        MemberInfo result = consultationAppointmentsService.selectAllByPage(memberId);
        if (result!= null) {
            return R.ok(result);
        }
        return R.error("查询预约失败");
    }
}
